package com.huaqin.obeacons;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;

import com.huaqin.obeacons.utils.MyDatabaseUtil;
import com.huaqin.obeacons.utils.MyPushIntentService;
import com.huaqin.obeacons.utils.SharedPreferenceUtil;
import com.umeng.message.PushAgent;

public class WelcomActivity extends BaseActivity {
	private final String TAG = "WelcomActivity";
	private static Context mContext;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_welcom);
		mContext = getApplicationContext();
		// 消息推动初始化begin
		PushAgent mPushAgent = PushAgent.getInstance(this);
		mPushAgent.onAppStart();
		mPushAgent.enable();
		mPushAgent.setPushIntentServiceClass(MyPushIntentService.class);
		// 消息推送初始化end

		new Handler().postDelayed(new Runnable() {

			public void run() {
				Intent mIntent = null;
				if (SharedPreferenceUtil.accountIsEmpty(mContext)) {
					mIntent = new Intent(mContext, LoginActivity.class);
				} else {
					mIntent = new Intent(mContext, MainTabActivity.class);
				}

				if (!SharedPreferenceUtil.getFirstStartFlag(mContext)) {
					MyDatabaseUtil.DatabaseInit(mContext);
					MyDatabaseUtil.insertDefaultMSG();
					SharedPreferenceUtil.setFirstStartFlag(mContext, true);
				}

				mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
						| Intent.FLAG_ACTIVITY_CLEAR_TOP);
				getApplicationContext().startActivity(mIntent);
				finish();
			}
		}, 1800);
	}

}
